package com.duan.search.listener;

import com.alibaba.fastjson.JSONObject;
import com.duan.entity.Result;
import com.duan.goods.feign.ProductFeign;
import com.duan.goods.pojo.Detail;
import com.duan.search.config.RabbitMqConfig;
import com.duan.search.mapper.ESManagerMapper;
import com.duan.search.pojo.DetailIndex;
import com.duan.search.service.ESManagerService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SearchListener {
    @Autowired
    private ProductFeign productFeign;

    @Autowired
    private ESManagerService esManagerService;

    @RabbitListener(queues = RabbitMqConfig.GOODS_QUEUE)
    public void product(String id){

        esManagerService.createMappingAndIndex();
        esManagerService.importById(id);
    }

    @RabbitListener(queues = RabbitMqConfig.GOODS_DOWN_QUEUE)
    public void goodsDownListener(String id) {
        esManagerService.deleteById(id);
    }
}
